package com.styles.codingstyle.utils;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 陈建
 * @Description: 手动异常信息封装(未完成)
 * @date 2018/5/24 10:41
 */
public class BindingResult_utils {

    /**
     * @param result
     * @return
     */
    public static Object fieldErrorsMessages(BindingResult result) {
        ArrayList<String> messages = new ArrayList<>();
        if (result.hasFieldErrors()) {
            List<FieldError> fieldErrors = result.getFieldErrors();
            for (FieldError fieldError : fieldErrors) {
                String message = fieldError.getDefaultMessage();
                messages.add(message);
            }
        }
        if (messages.size() != 0) {
            return messages;
        }
        return null;

    }
}
